package com.fqdf.framework.android.util;

import android.content.Context;

import com.bumptech.glide.Glide;
import com.bumptech.glide.GlideBuilder;
import com.bumptech.glide.integration.okhttp3.OkHttpUrlLoader;
import com.bumptech.glide.load.DecodeFormat;
import com.bumptech.glide.load.engine.cache.ExternalCacheDiskCacheFactory;
import com.bumptech.glide.load.model.GlideUrl;
import com.bumptech.glide.module.GlideModule;

import java.io.InputStream;

/**
 * Created
 * glide的全局设定
 */
public class MyGlideModule implements GlideModule {
    @Override
    public void applyOptions(Context context, GlideBuilder builder) {
        // 设定glide的编码设置
        builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888);
        // 设定glide的硬盘缓存
        builder.setDiskCache(new ExternalCacheDiskCacheFactory(context, "diskCache", 200 * 1024 * 1024));

    }

    @Override
    public void registerComponents(Context context, Glide glide) {
        // 设置glide网络请求为okhttp
        glide.register(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory());
    }
}
